package com.kaduoxee.ebooks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kaduoxee.ebooks.entity.Fiction;
import com.kaduoxee.ebooks.mapper.FictionMapper;
import com.kaduoxee.ebooks.service.FictionService;
import org.springframework.stereotype.Service;

@Service
public class FictionServiceImpl extends ServiceImpl<FictionMapper, Fiction>
        implements FictionService {

    /**
     * @param url 小说源数据url
     * @return url对应fiction
     */
    public Fiction getLFicByUrl(String url) {
        QueryWrapper<Fiction> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url",url);
        return getOne(queryWrapper);

    }

    /**
     * 更新某本小说的最新章节(fiction表)
     * @param newest 源数据（小说源）的最新章节
     * @param fictionId db中对应小说的id
     */
    public boolean updateFicNewest(String newest,Integer fictionId) {
        UpdateWrapper<Fiction> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("newest", newest).eq("id",fictionId);
        return update(updateWrapper);
    }
}
